#include <stdio.h>

int main(int argc,char const *argv[])
{
    FILE* file = fopen("user.txt","a+");
    if (file == NULL)
    {
        printf("打开文件失败！\n");
    }
    else
    {
        printf("打开文件成功！（%p)\n",file);
    }
// 从文件中读取一行字符串，并格式化到多个变量中
  char name[50];
  char wife;
  int code;
  printf("号码--代号-----姓名\r\n");
  while(fscanf(file, "%d %c %s",&code,&wife,name) != EOF)
  {
    printf("%d\t%c\t%s\n", code,wife,name);
}
    // 关闭文件
    int ret = fclose(file);
    if (ret == 0) 
    {
        printf("关闭文件成功！\n");
    }
    else
    {
        printf("关闭文件失败！\n");
    }
    
    return 0;
}